package com.study.userserviceprovider.dto;

import com.study.exception.ValidException;
import lombok.Data;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import javax.validation.constraints.NotNull;

/**
 * @description：登录dto
 * @author：李军荣
 * @date: 2020/12/28 10:45
 */
@Data
public class AuthLoginDto {

    private String userName;
    private String password;

    private String phone;
    private String code;

    private String openId;

    /**
     * @see com.study.userserviceprovider.enums.LoginTypeEnum
     */
    @NotNull(message = "登录类型不能为空")
    private Integer loginType;


    public void validData(BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            StringBuilder stringBuilder=new StringBuilder();
            for(ObjectError oe:bindingResult.getAllErrors()){
                stringBuilder.append(oe.getDefaultMessage()+"\n");
            }
            throw new ValidException(stringBuilder.toString());
        }
    }
}
